from django.contrib import admin
from .models import Medicine, MedicineCategory, MyMedicine, ScanRecord

@admin.register(Medicine)
class MedicineAdmin(admin.ModelAdmin):
    list_display = ('name', 'barcode', 'category', 'verified', 'view_count', 'scan_success_count', 'created_at')
    list_filter = ('category', 'verified', 'created_at')
    search_fields = ('name', 'barcode', 'brand')
    readonly_fields = ('view_count', 'scan_success_count', 'last_viewed_at')

@admin.register(MedicineCategory)
class MedicineCategoryAdmin(admin.ModelAdmin):
    list_display = ('name', 'parent', 'sort_order', 'created_at')
    list_filter = ('created_at',)
    search_fields = ('name',)

@admin.register(MyMedicine)
class MyMedicineAdmin(admin.ModelAdmin):
    list_display = ('medicine', 'family', 'status', 'quantity', 'expiry_date', 'usage_frequency', 'reminder_enabled')
    list_filter = ('status', 'family', 'reminder_enabled', 'created_at')
    search_fields = ('medicine__name', 'family__name')
    readonly_fields = ('last_inventory_check', 'usage_frequency')

@admin.register(ScanRecord)
class ScanRecordAdmin(admin.ModelAdmin):
    list_display = ('user', 'family', 'barcode', 'medicine', 'success', 'created_at')
    list_filter = ('success', 'created_at')
    search_fields = ('user__username', 'barcode')